﻿using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Search;
using Lemon_Note.Properties;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace Lemon_Note
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            FullScreenManager.RepairWpfWindowFullScreenBehavior(this);
        }
        
        private void MOVE(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
                this.DragMove();
            if (e.LeftButton == MouseButtonState.Released)
            {
                Settings.Default.top = this.Top;
                Settings.Default.left = this.Left;
                Settings.Default.Height = this.ActualHeight;
                Settings.Default.Width = this.ActualWidth;
                Settings.Default.Save();
            }
        }

        private void CLOSE(object sender, MouseButtonEventArgs e)
        {
            Environment.Exit(0);
        }
        private void MAX(object sender, MouseButtonEventArgs e)
        {
            if (this.WindowState == WindowState.Maximized) {
                this.WindowState = WindowState.Normal; }
            else
            {
                this.WindowState = WindowState.Maximized;
            }
        }
        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            Page.Clip = new RectangleGeometry() { RadiusX = 5, RadiusY = 5, Rect = new Rect() { Width = Page.ActualWidth, Height = Page.ActualHeight } };
        }
        private void MIN(object sender, MouseButtonEventArgs e)
        {
            WindowState = WindowState.Minimized;
        }

        private void textBox_TextChanged(object sender, EventArgs e)
        {
            Settings.Default.text = textBox.Text;
            t.Text = $"字符统计:{textBox.Text.Length}";
            Settings.Default.Save();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Settings.Default.Save();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            textBox1.Text = Settings.Default.code;
            textBox.SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension(Settings.Default.code);
            this.Height = Settings.Default.Height;
            this.Width = Settings.Default.Width;
            Top = Settings.Default.top;
            Left = Settings.Default.left;
            textBox.Text = Settings.Default.text;
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Settings.Default.code = textBox1.Text;
                Settings.Default.Save();
                textBox.SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension(Settings.Default.code);
            }
        }
    }
}
